/**
 * TO BE DETERMINED 
 */
package org.eichar.client.shared;

import java.util.AbstractSet;
import java.util.Iterator;
import java.util.Set;

/**
 * Since gwt doesn't have an Collections.unmodifiable* then this class takes
 * care of the unmodifiable set.
 * 
 * @author Jesse
 */
public class UnmodifiableSet extends AbstractSet implements Set {

    private final Set delegate;

    public UnmodifiableSet(final Set delegate) {
        super();
        this.delegate = delegate;
    }

    /**
     * @see java.util.AbstractCollection#iterator()
     */
    public Iterator iterator() {
        final Iterator iterator = delegate.iterator();
        return new Iterator() {

            public boolean hasNext() {
                return iterator.hasNext();
            }

            public Object next() {
                return iterator.next();
            }

            public void remove() {
                throw new UnsupportedOperationException();
            }

        };
    }

    /**
     * @see java.util.AbstractCollection#size()
     */
    public int size() {
        return delegate.size();
    }
}
